<template>
  <div class="nav-bar" :class="{isFixed: isFixed}">
    <div class="container">
      <div class="pro-title">{{title}}</div>
      <div class="pro-param">
        <a href="javascript: ;">概述</a><span>|</span>
        <a href="javascript: ;">参数</a><span>|</span>
        <a href="javascript: ;">用户评价</a>
        <slot name="buy"></slot>
      </div>
    </div>
  </div>
</template>

<script>
  export default {
    name: 'nav-bar',
    props: {
      title: String
    },
    data() {
      return {
        isFixed: false
      }
    },
    methods: {
      initHeight() {
        let scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop
        if (scrollTop >= 152) {
          this.isFixed = true
        } else {
          this.isFixed = false
        }
      }
    },
    mounted() {
      window.addEventListener('scroll', this.initHeight)
    },
    destroyed() {
      window.removeEventListener('scroll', this.initHeight, false)
    }
  }
</script>

<style lang='scss' scoped>
  @import './../assets/scss/config.scss';
  @import './../assets/scss/mixin.scss';
  .nav-bar{
    &.isFixed{
      top: 0;
      position: fixed;
      background: $colorG;
      z-index: 12;
    }
    width: 100%;
    height: 70px;
    border-top: 1px solid $colorH;
    box-shadow: 0 5px 5px #e0e0e0;
    .container{
      @include flex();
      height: 100%;
      .pro-title{
        color: $colorB;
        font-size: 18px;
        font-weight: bold;
      }
      .pro-param{
        a{
          margin: 0 10px;
          color: $colorC;
        }
        .btn{
          cursor: pointer;
        }
      }
    }
  }
</style>